package com.onpositive.wikidataeditor;

import org.eclipse.jface.action.Action;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.ui.IWorkbenchWindow;

import com.onpositive.wikistorage.XMLInterface;


public class SaveViewAction extends Action {
	
	private final IWorkbenchWindow window;
	private final String viewId;
	
	public SaveViewAction(IWorkbenchWindow window, String label, String viewId) {
		this.window = window;
		this.viewId = viewId;
        setText(label);
        // The id is used to refer to the action in a menu or toolbar
		setId(ICommandIds.CMD_SAVE);
        // Associate the action with a pre-defined command, to allow key bindings.
		setActionDefinitionId(ICommandIds.CMD_SAVE);
		setImageDescriptor(com.onpositive.wikidataeditor.Activator.getImageDescriptor("/icons/sample.gif"));
	}
	
	public void run() {
		if(window != null) {	

				//window.getActivePage().showView(viewId, Integer.toString(instanceNum++), IWorkbenchPage.VIEW_ACTIVATE);
				FileDialog fd = new FileDialog( window.getShell(), SWT.SAVE);
		        fd.setText("Save AS");
		        fd.setFilterPath("C:/");
		        String[] filterExt = { "*.xml", "*.txt" };
		        fd.setFilterExtensions(filterExt);
		        String path = fd.open();
		        
		        XMLInterface.saveParsedCategory( path, Resources.getInstance().getWorkingCategory(), 0 ) ;
		        		        
		 }	
	}
}
